<?php
namespace app\api\model;


use app\model\Base;

class UserCommonLog extends Base
{
    public static function induce($userId, $amount)
    {
        /**
         * TODO
         * $type 判断是否需要手续费
         * 手续费比例后台配置，直接获取后台手续费比例
         * 加手续费字段，扣除手续费逻辑
         */
        $add = [];
        $add['user_id'] = $userId;
        $add['amount'] = $amount;

        self::create($add);
        return true;
    }

    /**createOrder
     * 领取收益
     * @return \think\response\Json
     * @throws
     */
    public static function getGold($userId)
    {
//        $h = date('H', time());
//        $h = (int)$h;
        $total = self::where('user_id', $userId)
            ->whereNull('get_time')
            ->sum('amount');

        $res = self::where('user_id', $userId)
            ->whereNull('get_time')
            ->update(['get_time' => date('Y-m-d H:i:s')]);
        if($res > 0){
            //induce($userId, $amount, $wallet_type = 0, $wallet_des = 0, $alias = 'money', $des = '')
            User::induce($userId, $total, 9, 9, $alias = 'gold');
            return $total;
        }else{
            return 0;
        }
    }
}